﻿
using Net.http;
using System; 

namespace HBase {
    public class LoggerCommon {

        public static bool loggerMongon = true;
        public static bool loggerInfoLoggerFile = true;
        public static bool loggerMyConsole = false;
        //file mongo cline cosonle

     


        public static void consoleOnly(int code,String format, params object[] p) {
            if (String.IsNullOrWhiteSpace(format)) {
                return;
            }
            if (p.Length > 0) {
                format = String.Format(format, p);
            }
            MyConsole.addMessage(format);
            LoggerCache.has(code,format);
        }
        public static void consol(int code,String format, params object[] p) {
            if (String.IsNullOrWhiteSpace(format)) {
                return;
            }
            if (p.Length > 0) {
                format = String.Format(format, p);
            }
          
            if (LoggerCache.has(code,format)) {
                return;
            }
            MyConsole.addMessage(format);
            if (LoggerCommon.loggerMongon) {
                GuidangCache.addMessage(format);
            } 
            if (LoggerCommon.loggerInfoLoggerFile) {
                FileLogger.Error(format, null);
            }
        }

        public static void fileAll(int code,String format, params object[] p) {
            if (String.IsNullOrEmpty(format)) {
                return;
            }
            if (p.Length > 0) {
                format = String.Format(format, p);
            }
            MyConsole.addMessage(format);
            LoggerCache.has(code,format);
            if (LoggerCommon.loggerMongon) {
                GuidangCache.addMessage(format);
            }
            if (LoggerCommon.loggerInfoLoggerFile) {
                FileLogger.Error(format, null);
            }
        }


        public static void error(int code,string s, Exception ex) {//mongo 
            if (String.IsNullOrEmpty(s)) {
                return;
            }
            FileLogger.Error(s, ex);
            MyConsole.addMessage(s);
            GuidangCache.addMessage(s + ex.Message);

           
            LoggerCache.has(code,s);
        }

       
      

        public static void startError(int code,string s, Exception ex) {//启动异常，dll无法加载 等系统无法启动时使用
            if (String.IsNullOrEmpty(s)) {
                return;
            }
            MyConsole.addMessage(s);
            LoggerCache.has(code,s);
            FileLogger.Error(s, ex); 
        }
     
       

       
    }
}
